CC=arm-elf-gcc
OBJCOPY=arm-elf-objcopy
LDSCRIPT=ldscript.ld
TARGET=SELivre-2478-platform

LINKER_FLAGS=-mthumb -nostartfiles -Xlinker -o${TARGET}.elf -Xlinker -M -Xlinker -Map=${TARGET}.map

DEBUG=-g
OPTIM=-O1


CFLAGS= \
		$(DEBUG) \
		$(OPTIM) \
		-T$(LDSCRIPT) \
		-I . \
		-mcpu=arm7tdmi \
		-D PACK_STRUCT_END=__attribute\(\(packed\)\) \
		-D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) \
		-fomit-frame-pointer \
		-mthumb-interwork
										
THUMB_SOURCE= \

#		./lcd/pic/SELivre-LTF430-Logo.c


ARM_SOURCE= \
		main.c \
		./uart/uart.c \
		./mprintf/mprintf.c \
		./sdram/sdram.c \
		./lcd/lcd_driver.c \
		./timer/timer.c \
		./touchscreen/touchscreen.c \
		./adc/adc.c \
		./fdraw/fdraw.c

		

THUMB_OBJS = $(THUMB_SOURCE:.c=.o)
ARM_OBJS = $(ARM_SOURCE:.c=.o)


all: ${TARGET}.bin isp

${TARGET}.bin : ${TARGET}.hex
	$(OBJCOPY) ${TARGET}.elf -O binary ${TARGET}.bin
	 
${TARGET}.hex : ${TARGET}.elf
	$(OBJCOPY) ${TARGET}.elf -O ihex ${TARGET}.hex

${TARGET}.elf : $(THUMB_OBJS) $(ARM_OBJS) boot.s Makefile
	$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(LIBS) boot.s $(LINKER_FLAGS) 

$(THUMB_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) -mthumb $< -o $@

$(ARM_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) $< -o $@

clean :
	rm -f $(THUMB_OBJS) $(ARM_OBJS) ${TARGET}.elf ${TARGET}.hex ${TARGET}.bin ${TARGET}.map

isp:
	lpc21isp ${TARGET}.hex /dev/ttyUSB0 115200 11059
